package com.supergzt.handler;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.supergzt.context.SecurityContextHolder;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author 张钧
 * @Description
 * @create 2023-01-09 17:34
 */
@Component
public class MyBatisMetaObjectHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
		this.strictInsertFill(metaObject, "createdBy", String.class, SecurityContextHolder.getUserName());
		this.strictInsertFill(metaObject, "createdTime", LocalDateTime::now, LocalDateTime.class);
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		this.strictUpdateFill(metaObject, "updatedBy",String.class,SecurityContextHolder.getUserName());
		this.strictUpdateFill(metaObject, "updatedTime", LocalDateTime::now, LocalDateTime.class);
	}
}
